package com.gp.testonline.service.impl;

import com.gp.testonline.dao.QuestioninfoMapper;
import com.gp.testonline.eo.QuestioninfoEOPage;
import com.gp.testonline.model.Questioninfo;
import com.gp.testonline.service.QuestioninfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 接口方法的实现
 */
@Service
public class QuestioninfoImpl implements QuestioninfoService {
    @Autowired
    private QuestioninfoMapper questioninfoMapper;

    @Override
    public int InsertQuestioninfo(Questioninfo questioninfo) {
        /*
         * 业务判断
         * 试题内容不能重复
         */
        int returnInt=0;
        try{
            if (questioninfoMapper.getQuestioninfoCount(questioninfo.getQicontent())<1){
            returnInt=questioninfoMapper.insertQuestionInfo(questioninfo);}else {
                returnInt=-1;
            }
        }catch (Exception e){
            returnInt=-1;
            System.out.println("添加试题信息时执行sql报错，信息为："+e.getMessage());
        }
        return returnInt;
    }

    @Override
    public int UpdateQuestioninfo(Questioninfo questioninfo) {
        int isUpdate=0;
        try{
            isUpdate=questioninfoMapper.updateQuestioninfo(questioninfo);
        }catch (Exception e){
            isUpdate=-1;
            //打印更新时报错的情况
            System.out.println("更新试题信息时执行sql报错的原因为："+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int DeleteQuestioninfo(int qiid) {
        int isDelete=0;
        /*1 没有相关业务流程的判断*/
        try{
            isDelete=questioninfoMapper.deleteQuestioninfo(qiid);
        }catch (Exception e){
            isDelete=-1;
            //打印更新时报错的情况
            System.out.println("删除试题信息时执行sql报错的原因为："+e.getMessage());
        }
        return isDelete;
    }

    @Override
    public List<QuestioninfoEOPage> getQuestioninfoAll(QuestioninfoEOPage questioninfoEOPage) {
        List<QuestioninfoEOPage> listQuestioninfoEo=questioninfoMapper.getQuestioninfoAll(questioninfoEOPage);
        return listQuestioninfoEo;
    }
}
